/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Business;

import Connections.Database;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author manhnv_b00954
 */
public class LoginManage extends Database{
    Connection conn;
    public LoginManage() {
    }
    public String LoginValidate(String userName,String password) {
        String userType = null;
        ResultSet rs = null;
        try {
            
            conn = getConn();
            String sql = "SELECT username, password, usertype FROM Administrator WHERE userName = ? AND password = ?";
            PreparedStatement preStm = conn.prepareStatement(sql);
            preStm.setString(1, userName);
            preStm.setString(2, password);
            rs = preStm.executeQuery();
            while (rs.next()) {
                userType = rs.getString(3);
            }
            rs.close();
            closeConn();
        } catch (SQLException ex) {
            System.out.println("SAi pass");
            //JOptionPane.showMessageDialog(null, "Khong dang nhap dc !");
           // Logger.getLogger(LoginManage.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex){
            System.out.println("Login model error !");
        }
        
        return userType;

    }
}
